package com.lmh.graphdisease.repository;

import com.lmh.graphdisease.entity.DrugEntity;
import org.neo4j.driver.internal.value.NodeValue;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author lmh
 * @desc
 * @date 2023/3/9
 */
@Repository
public interface DrugRepository extends Neo4jRepository<DrugEntity,Long> {


    /**
     *@author lmh
     *@date 2023/3/9
     *@desc 找到当前药品的生产厂家
     */
    @Query("MATCH(n:Drug)<-[r:drugs_of]-(nn:Producer) WHERE n.name = $0 RETURN nn LIMIT $1")
    List<NodeValue> getDrugOf(String name,int num);

    @Query("MATCH (n:Drug) RETURN n SKIP $0 LIMIT $1")
    List<DrugEntity> getNumDrug(int page, int size);

    @Query("MATCH (n:Drug) RETURN count(*)")
    Integer getDrugNum();

    @Query("CREATE(f:Drug {name:$0})")
    void addDrug(String name);

    @Query("MATCH (f:Drug) WHERE f.name = $0 RETURN f")
    DrugEntity getDrugByName(String name);

    @Query("MATCH(f:Drug{name:$0}) DELETE f")
    void deleteByName(String name);

}
